<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
	<head>
		<title></title>
		<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
		<link href="gadget.css" rel="stylesheet" type="text/css" />
	</head>

	<script type="text/javascript" language="javascript">
		function settingsClosed()
		{ //code to update your gadget
		  readSettings();
		}

		function initGadget()
		{
			System.Gadget.settingsUI = "settings.htm";
			System.Gadget.onSettingsClosed = settingsClosed;

			checkState();
			System.Gadget.onDock = checkState;
			System.Gadget.onUndock = checkState;

			readSettings();
			calcTime(); //--> DO NOT CALL THIS ELSEWHERE OR YOU'LL HAVE TIMER HELL!
		}

		var timeZones;
		var extraOffset = 0;
		var dstOffset = 0; // Daylight Savings Time
		var headline = "Utc";
		function readSettings()
		{
			timeZones = System.Time.timeZones;
			extraOffset = parseInt(System.Gadget.Settings.readString("minDiff")) || 0;
			headline = System.Gadget.Settings.readString("headline") || 'Utc';

			dstOffset = 0; // Daylight Savings Time
			var zone = System.Gadget.Settings.readString("diffName") || "(UTC) Coordinated Universal Time";
			if (zone != "(UTC) Coordinated Universal Time") // Might have DST
				for (var num = 0; num < timeZones.count; num++)
				{
					if (zone == timeZones.item(num).displayName)
						dstOffset = timeZones.item(num).DSTBias;
				}

			// Drop shadow
			var dropCol = System.Gadget.Settings.readString("dropShadowColor") || "666666";
			var dropDir = System.Gadget.Settings.readString("dropShadowDirection") || "135";
			if (parseBool(System.Gadget.Settings.readString("dropShadow") || "True"))
				headlineText.style.filter = "Shadow(Color=#" + dropCol + ", Direction=" + dropDir + ")";
			else
				headlineText.style.filter = "none";

			// Colors
			headlineText.style.color = (System.Gadget.Settings.readString("headlineColor") || 'cccccc');
			noonText.style.color = (System.Gadget.Settings.readString("miscColor") || '999999');
			dayText.style.color = (System.Gadget.Settings.readString("miscColor") || '999999');
			dateText.style.color = (System.Gadget.Settings.readString("miscColor") || '999999');
			
			// Number Style
			var nStyle = System.Gadget.Settings.readString("style") || "digital";
			document.getElementById("num-").src = '_gfx/' + nStyle + '_-.png';
			for (i=0; i < 10; i++)
				document.getElementById("num" + i).src = '_gfx/' + nStyle + '_' + i + '.png';
			
			// Change dots here as we don't change them in our update
			imgSep1.src = document.getElementById("num-").src;
			imgSep2.src = document.getElementById("num-").src;
			
			// Fonts
			headlineText.style.fontFamily = System.Gadget.Settings.readString("hFont") || "'Adventure', 'trebuchet ms', verdana, arial, helvetica, sans-serif";
			headlineText.style.fontSize = System.Gadget.Settings.readString("hFontSize") || "28";
			noonText.style.fontFamily = System.Gadget.Settings.readString("mFont") || "'trebuchet ms', verdana, arial, helvetica, sans-serif";
			noonText.style.fontSize = System.Gadget.Settings.readString("mFontSize") || "10";
			dayText.style.fontFamily = System.Gadget.Settings.readString("mFont") || "'trebuchet ms', verdana, arial, helvetica, sans-serif";
			dayText.style.fontSize = System.Gadget.Settings.readString("mFontSize") || "10";
			dateText.style.fontFamily = System.Gadget.Settings.readString("mFont") || "'trebuchet ms', verdana, arial, helvetica, sans-serif";
			dateText.style.fontSize = System.Gadget.Settings.readString("mFontSize") || "10";
		}

		function debug()
		{ // Called last in each update usable for testing stuff :)
			 return;
			 document.getElementById("headlineText").innerHTML = '';
		}

		function calcTime()
		{  //--> DO NOT CALL THIS ANY PLACE OTHER THEN initGadget OR YOU'LL HAVE TIMER HELL!
			var wdName_long = ["Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday"];
			var wdName_short = ["Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat"];
			var mName_long = ["January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December"];
			var mName_short = ["Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"];

			var dteCurrent = new Date();
			var utcTime = dteCurrent.getTime() + (dteCurrent.getTimezoneOffset() * 60000);
			var utcDate = new Date(utcTime);

			var thisTime = utcDate.getTime() + (extraOffset * -1 * 60000) + (dstOffset * -1 * 60000);
			var thisDate = new Date(thisTime);
			var ap = 'AM';
			if (thisDate.getHours() > 11)
				ap = 'PM';

			var hour1 = PadDigits(thisDate.getHours(), 2).substring(0, 1);
			var hour2 = PadDigits(thisDate.getHours(), 2).substring(1, 2);
			var minute1 = PadDigits(thisDate.getMinutes(), 2).substring(0, 1);
			var minute2 = PadDigits(thisDate.getMinutes(), 2).substring(1, 2);
			var second1 = PadDigits(thisDate.getSeconds(), 2).substring(0, 1);
			var second2 = PadDigits(thisDate.getSeconds(), 2).substring(1, 2);

			headlineText.innerHTML = headline;
			imgHour1.src = document.getElementById("num" + hour1).src;
			imgHour2.src = document.getElementById("num" + hour2).src;
			imgMinute1.src = document.getElementById("num" + minute1).src;
			imgMinute2.src = document.getElementById("num" + minute2).src;
			imgSecond1.src = document.getElementById("num" + second1).src;
			imgSecond2.src = document.getElementById("num" + second2).src;

			noonText.innerHTML = ap;

			dayText.innerHTML = wdName_long[thisDate.getDay()];//.toUpperCase();

			dateText.innerHTML = mName_long[thisDate.getMonth()]//.toUpperCase()
				+ ', ' + thisDate.getDate();

			setTimeout("calcTime()", 333);

			debug();
		}

		function PadDigits(n, totalDigits)
		{
			n = n.toString();
			var pd = '';
			if (totalDigits > n.length)
				for (i=0; i < (totalDigits-n.length); i++)
				{
					pd += '0';
				}

			return pd + n.toString();
		}

		function parseBool(val)
		{
			val = new String(val);
			val = val.toLowerCase();

			if(val== "1" || val=="-1" || val=="true" || val == "yes")
				return true;
			else
				return false;
		}

		function checkState()
		{
			if(!System.Gadget.docked)
				undockedState();
			else if (System.Gadget.docked)
				dockedState();
		}

		function undockedState()
		{

		}

		function dockedState()
		{

		}
	</script>

	<body onload="initGadget()">
		<div id="headlineText">Local</div>
		<div
			id="timeDigits">&nbsp;<img
			id="imgHour1" src="_gfx/digital_7.png"><img
			id="imgHour2" src="_gfx/digital_7.png"><img
			id="imgSep1" src="_gfx/digital_-.png"><img
			id="imgMinute1" src="_gfx/digital_0.png"><img
			id="imgMinute2" src="_gfx/digital_5.png"><img
			id="imgSep2" src="_gfx/digital_-.png"><img
			id="imgSecond1" src="_gfx/digital_0.png"><img
			id="imgSecond2" src="_gfx/digital_5.png"></div>
		<div id="noonText">PM</div>
		<div id="dayText">SATURDAY</div>
		<div id="dateText">MAY, 05</div>

		<div id="numbersHidden" style="visibility:hidden;">
			<img id="num0" src="_gfx/digital_0.png">
			<img id="num1" src="_gfx/digital_1.png">
			<img id="num2" src="_gfx/digital_2.png">
			<img id="num3" src="_gfx/digital_3.png">
			<img id="num4" src="_gfx/digital_4.png">
			<img id="num5" src="_gfx/digital_5.png">
			<img id="num6" src="_gfx/digital_6.png">
			<img id="num7" src="_gfx/digital_7.png">
			<img id="num8" src="_gfx/digital_8.png">
			<img id="num9" src="_gfx/digital_9.png">
			<img id="num-" src="_gfx/digital_-.png">
		</div>
	</body>
</html>